package db

import (
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
	log "github.com/sirupsen/logrus"
	"time"
)

func CreateConn(connStr string) (db *sql.DB, err error) {
	db, err = sql.Open("mysql", connStr)
	if err != nil {
		log.Error("连接数据库异常")
		return nil, err
	}
	db.SetMaxOpenConns(3)
	db.SetMaxIdleConns(1)
	db.SetConnMaxLifetime(7 * time.Hour)
	err = db.Ping()
	return
}
